import jQuery from 'jquery'

export const getQuery = () => {
  let urlArr = location.search.slice(1).split('&')
  let query = []
  urlArr.forEach(item => {
    // console.log(item.split('='))
    query.push(item.split('='))
  })
  return Object.fromEntries(query)
}

export const baseUrl = 'https://gank.io/api/v2'

export const myAjaxP = ({url} = {}) => {
  return new Promise((resolve, reject) => {
    jQuery.ajax({
      url: `https://gank.io/api/v2${url}`,
      success(result) {
        resolve(result)
      },
      error(e) {
        reject(e)
      }
    })
  })
}

/*export const myAjax = ({url, method = 'GET', success, error}) => {
  jQuery.ajax({
    url: `${baseUrl}${url}`,
    type: method,
    success(res) {
      success(res)
    },
    error(e) {
      error(e)
    }
  })
}*/

